import type { PlasmoMessaging } from "@plasmohq/messaging"

const NEWS_API_URL = "https://jsonplaceholder.typicode.com/posts"

export default async (req, res) => {
  try {
    const { count = 5 } = req.body || {}
    const response = await fetch(`${NEWS_API_URL}?_limit=${count}`)
    const data = await response.json()
    res.send({ success: true, data })
  } catch (error) {
    res.send({ success: false,error: error instanceof Error ? error.message : "获取失败"})
  }
}